
// 下面是 结果转表单
const textFmt = function (value) {
  var dataAt = value.replace(/(\\r\\n)|(\\n)/g, '<br>');
  return dataAt;
};
const json2HtmlDom = function (kvs, obj) {
  var html = '<div class="form-util">';
  var keys = Object.keys(kvs);
  for (let i = 0; i < keys.length; i++) {
    let k = kvs[keys[i]];
    let key = '';
    let value = '';
    let clz = '';
    let fmt = '';
    if (k instanceof Array) {
      key = k[0];
      clz = k[1] || '';
      fmt = k[2];
    } else {
      key = k;
    }
    value = obj[keys[i]] || '--';
    if (fmt) {
      value = fmt(value);
    }
    // fmt && (value = fmt(value));
    html += `
      <div class="item">
        <div class="key">${key}</div>
        <div class="value ${clz}">${value}</div>
      </div>
    `;
  }
  html += '</div>';
  return html;
};
// 结果转表单 Version2 多块内容
const json2HtmlDomV2 = function (kvs, obj) {
  var html = '<div class="form-block">';
  var keys = Object.keys(kvs);
  for (let i = 0; i < keys.length; i++) {
    let k = kvs[keys[i]];
    let label = k.label;
    html += `<div class="form-label">${label}</div>`;
    html += obj[keys[i]] ? json2HtmlDom(k.kvs, obj[keys[i]]) : `<div class="tip">无[${label}]相关数据</div>`;
  }
  html += '</div>';
  return html;
};
const picFmt = function (picArr) {
  var result = "";
  picArr.forEach(element => {
    result += `<img src="${element}"><br>`;
  });
  return result;
};
export default {
  picFmt,
  textFmt,
  json2HtmlDom,
  json2HtmlDomV2
};
